﻿Imports System.Data.OleDb

Public Class AddResearch
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_addSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_addSubmit.Click
        Dim firstPagePictureGuid As New System.Guid
        firstPagePictureGuid = Guid.NewGuid()
        Dim newFirstPagePictureName = firstPagePictureGuid.ToString() + ".jpg"
        If fu_picture.HasFile Then
            Dim imageLocation = Request.MapPath("Images") & "/" & newFirstPagePictureName
            fu_picture.SaveAs(imageLocation)
        End If

        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim sql = "INSERT INTO Researches (Title,AddedBy,FieldOfStudy,University,FirstPagePicture,Contact,Description,Rating) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8)"
        Dim cmdDB = New OleDbCommand(sql, conn)
        cmdDB.Parameters.AddWithValue("@f1", tb_title.Text)
        cmdDB.Parameters.AddWithValue("@f2", User.Identity.Name)
        cmdDB.Parameters.AddWithValue("@f3", tb_category.Text)
        cmdDB.Parameters.AddWithValue("@f4", tb_university.Text)
        cmdDB.Parameters.AddWithValue("@f5", "Images/" & newFirstPagePictureName)
        cmdDB.Parameters.AddWithValue("@f6", tb_emailAddress.Text)
        cmdDB.Parameters.AddWithValue("@f7", tb_note.Text)
        cmdDB.Parameters.AddWithValue("@f8", rbl_rating.SelectedValue)
        conn.Open()
        cmdDB.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("AddSucceeded.aspx")
    End Sub
End Class